package com.tykboot.entity;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tykboot.core.base.BaseEntity;
import com.tykboot.model.CurrencyAmount;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
 * @author LiuYu
 */
@Entity
@Table(name = "tb_standing_order")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class TbStandingOrder extends BaseEntity {

    /**
     *
     */
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(name = "standingOrderId")
    private String standingOrderId;

    /**
     *
     */
    @JsonIgnore
    @Column(name = "financialId")
    private String financialId;

    /**
     *
     */
    @Column(name = "accountId")
    private String accountId;

    /**
     *
     */
    @Column(name = "frequency")
    private String frequency;

    /**
     *
     */
    @Column(name = "reference")
    private String reference;

    /**
     *
     */
    @Column(name = "firstPaymentDateTime")
    private Date firstPaymentDateTime;

    /**
     *
     */
    @JsonIgnore
    @Column(name = "firstPaymentAmount")
    private String firstPaymentAmountDb;

    /**
     *
     */
    @Column(name = "nextPaymentDateTime")
    private Date nextPaymentDateTime;

    /**
     *
     */
    @JsonIgnore
    @Column(name = "nextPaymentAmount")
    private String nextPaymentAmountDb;

    /**
     *
     */
    @Column(name = "finalPaymentDateTime")
    private Date finalPaymentDateTime;

    /**
     *
     */
    @JsonIgnore
    @Column(name = "finalPaymentAmount")
    private String finalPaymentAmountDb;

    @Transient
    private CurrencyAmount firstPaymentAmount;

    @Transient
    private CurrencyAmount nextPaymentAmount;

    @Transient
    private CurrencyAmount finalPaymentAmount;

    @Transient
    private TbAccountServicer servicer;

    @Transient
    private TbAccountDetail creditorAccount;

    public String getStandingOrderId() {
        return standingOrderId;
    }

    public void setStandingOrderId(String standingOrderId) {
        this.standingOrderId = standingOrderId;
    }

    public String getFinancialId() {
        return financialId;
    }

    public void setFinancialId(String financialId) {
        this.financialId = financialId;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getFrequency() {
        return frequency;
    }

    public void setFrequency(String frequency) {
        this.frequency = frequency;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public Date getFirstPaymentDateTime() {
        return firstPaymentDateTime;
    }

    public void setFirstPaymentDateTime(Date firstPaymentDateTime) {
        this.firstPaymentDateTime = firstPaymentDateTime;
    }

    public String getFirstPaymentAmountDb() {
        return firstPaymentAmountDb;
    }

    public void setFirstPaymentAmountDb(String firstPaymentAmountDb) {
        this.firstPaymentAmountDb = firstPaymentAmountDb;
    }

    public Date getNextPaymentDateTime() {
        return nextPaymentDateTime;
    }

    public void setNextPaymentDateTime(Date nextPaymentDateTime) {
        this.nextPaymentDateTime = nextPaymentDateTime;
    }

    public String getNextPaymentAmountDb() {
        return nextPaymentAmountDb;
    }

    public void setNextPaymentAmountDb(String nextPaymentAmountDb) {
        this.nextPaymentAmountDb = nextPaymentAmountDb;
    }

    public Date getFinalPaymentDateTime() {
        return finalPaymentDateTime;
    }

    public void setFinalPaymentDateTime(Date finalPaymentDateTime) {
        this.finalPaymentDateTime = finalPaymentDateTime;
    }

    public String getFinalPaymentAmountDb() {
        return finalPaymentAmountDb;
    }

    public void setFinalPaymentAmountDb(String finalPaymentAmountDb) {
        this.finalPaymentAmountDb = finalPaymentAmountDb;
    }

    public CurrencyAmount getFirstPaymentAmount() {
        if (firstPaymentAmount != null) {
            return firstPaymentAmount;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getFirstPaymentAmountDb())), CurrencyAmount.class);
    }

    public void setFirstPaymentAmount(CurrencyAmount firstPaymentAmount) {
        this.firstPaymentAmount = firstPaymentAmount;
    }

    public CurrencyAmount getNextPaymentAmount() {
        if (nextPaymentAmount != null) {
            return nextPaymentAmount;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getNextPaymentAmountDb())), CurrencyAmount.class);
    }

    public void setNextPaymentAmount(CurrencyAmount nextPaymentAmount) {
        this.nextPaymentAmount = nextPaymentAmount;
    }

    public CurrencyAmount getFinalPaymentAmount() {
        if (finalPaymentAmount != null) {
            return finalPaymentAmount;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getFinalPaymentAmountDb())), CurrencyAmount.class);
    }

    public void setFinalPaymentAmount(CurrencyAmount finalPaymentAmount) {
        this.finalPaymentAmount = finalPaymentAmount;
    }

    public TbAccountServicer getServicer() {
        return servicer;
    }

    public void setServicer(TbAccountServicer servicer) {
        this.servicer = servicer;
    }

    public TbAccountDetail getCreditorAccount() {
        return creditorAccount;
    }

    public void setCreditorAccount(TbAccountDetail creditorAccount) {
        this.creditorAccount = creditorAccount;
    }
}

